﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace GSdk.Net.Lglcd
{
    /// <summary>
    /// This class provides a way to access to supported devices for given applet.
    /// Constructor should be called by derived classes.
    /// </summary>
    public abstract class DeviceCollection : IDisposable
    {
        protected Applet Parent { get; private set; }

        /// <summary>
        /// This constructor should be called by derived classes, it throws for parent == null and if SupportedDevices == Invalid. Assigns parent to Parent.
        /// </summary>
        /// <param name="parent"></param>
        public DeviceCollection(Applet parent)
        {
            if (parent == null)
                throw new ArgumentNullException();
            if (parent.SupportedDevices == DeviceTypes.Invalid)
                throw new AppletException("Applet doesn't support any device");

            Parent = parent;
        }

        /// <summary>
        /// This method allows a total overloading of device-retrive behaviour
        /// </summary>
        /// <param name="device">Device to retrive</param>
        /// <returns>Device</returns>
        public abstract Device this[DeviceTypes device] { get; }

        /// <summary>
        /// This method must be implemented because we want that our DeviceCollection will release any resources connected to the applet, but we don't know how is it done now.
        /// </summary>
        public abstract void Dispose();
    }
}
